package com.rinlink.jbcodec.transform;


import com.rinlink.jbcodec.exception.TransformException;

import java.nio.ByteBuffer;
import java.util.List;


public class ShortListToBytes extends NumberListToBytes {


    public ShortListToBytes(List<Short> list, String order) {
        super(list, order);
    }

    @Override
    public byte[] transform() throws TransformException {
        List<Short> list = getList();
        ByteBuffer buffer = ByteBuffer.allocate(list.size() * Short.BYTES);
        buffer.order(getOrder());
        buffer.order();
        for (int i = 0; i < list.size(); i++)
            buffer.putShort(list.get(i));
        return buffer.array();
    }

}
